package com.molichuxing.services.infrastructure.service.impl;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.molichuxing.services.infrastructure.bean.InsuranceCompanyBean;
import com.molichuxing.services.infrastructure.convertor.Convert;
import com.molichuxing.services.infrastructure.dao.InsuranceCompanyMapper;
import com.molichuxing.services.infrastructure.dto.response.InsuranceCompanyDto;
import com.molichuxing.services.infrastructure.service.InsuranceCompanyService;

/**
 * <p>
 * 保险服务实现类
 * </p>
 *
 * @author
 * @since 2019-08-12
 */
@Service("insuranceCompanyService")
public class InsuranceCompanyServiceImpl implements InsuranceCompanyService {

	@Resource
	private InsuranceCompanyMapper insuranceCompanyMapper;

	@Override
	public InsuranceCompanyDto getInsuranceCompanyName(Integer id) {
		// 根据保险公司ID 获取保险公司名称
		InsuranceCompanyBean insuranceCompanyBean = insuranceCompanyMapper.getById(id);
		return Convert.toInsuranceCompanyBeanDto(insuranceCompanyBean);
	}

	@Override
	public List<InsuranceCompanyDto> getInsurance() {
		return Convert.toInsuranceCompanyBeanDto(insuranceCompanyMapper.getInsuranceList());
	}

	@Override
	public InsuranceCompanyDto getInsuranceByName(String name) {
		return Convert.toInsuranceCompanyBeanDto(insuranceCompanyMapper.getInsuranceByName(name));
	}

	/**
	 * 查询保险公司名称
	 * 
	 * @param ids
	 *            保险公司ids
	 * @return
	 */
	@Override
	public Map<Integer, String> getInsuranceCompanyName(List<Integer> ids) {
		List<InsuranceCompanyBean> beans = insuranceCompanyMapper.getInsuranceCompanyName(ids);
		if (beans == null || beans.isEmpty()) {
			return null;
		}

		return beans.stream().collect(Collectors.toMap(InsuranceCompanyBean::getId, InsuranceCompanyBean::getName));
	}

}
